<template>
  <div class="con">
    <div class="box">
      <h2>登录</h2>
      <el-input v-model="user.username" placeholder="请输入内容"></el-input>
      <el-input
        placeholder="请输入密码"
        v-model="user.password"
        show-password
      ></el-input>
      <el-button type="primary" @click="login">登录</el-button>
    </div>
  </div>
</template>

<script>
import { requserlogin } from "../../http/api";
import { mapActions, mapGetters } from "vuex";
export default {
  data() {
    return {
      user: {
        username: "",
        password: "",
      },
    };
  },
  computed: {
    ...mapGetters({
    }),
  },
  methods: {
    ...mapActions({
      changeUserInfo: "changeUserInfo",
    }),
    login(){
    requserlogin(this.user).then(res => {
        // 存入vuex和本地存储
        this.changeUserInfo(res.data.list)
        this.$router.push('/')
    })
    
    }
  },
};
</script>

<style scoped lang="less">
@import "../../less/index.less";
.con {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(to right, @primary-light, @primary-deep);
}
.box {
  width: 300px;
  height: 250px;
  text-align: center;
  position: absolute;
  padding: 20px;
  left: 50%;
  top: 50%;
  background-color: #fff;
  transform: translate(-50%, -50%);
  h2 {
    text-align: center;
    margin-bottom: 20px;
  }
  .el-input {
    margin-bottom: 20px;
  }
  .el-button {
    text-align: center;
  }
}
</style>